package com.ktjy.test;

import com.ktjy.config.javaConfig;
import com.ktjy.entity.SysUser;
import com.ktjy.service.SysUserService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.List;

public class Main {
    Logger logger = LoggerFactory.getLogger(Main.class);

    @Test
    public void test1() {
       ApplicationContext context = new AnnotationConfigApplicationContext(javaConfig.class);

        SysUserService userService = (SysUserService)
                context.getBean("sysUserService");
        SysUser queryCondition = new SysUser();
        queryCondition.setRealName("李");
        queryCondition.setRoleId(2L);
        List<SysUser> userList = userService.getSysUserList(queryCondition);
        for (SysUser user : userList) {
            logger.info("SysUser: account={}, realName={}, roleName={}",
                    user.getAccount(), user.getRealName(),
                    user.getRole().getRoleName());
        }
    }
    @Test
    public void test2(){
        //1.获取spring的上下文对象
        ApplicationContext context = new
                ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        SysUserService sysUserService = (SysUserService)
                context.getBean("sysUserService");
        // 这里为了简单，只用两条数据测试效果即可
        SysUser user1 = new SysUser();
        user1.setAccount("ceshi1");
        user1.setRealName("测试用户1");
        SysUser user2 = new SysUser();
        user2.setAccount("ceshi2");
        user2.setRealName("测试用户2");
        List<SysUser> userList = Arrays.asList(user1, user2);
        // 测试保存数据
        sysUserService.saveBatch(userList);
    }
}
